package com.draemoncode.weixindb.service;

import com.draemoncode.weixindb.constant.PodFlagConstant;
import com.draemoncode.weixindb.domain.B_Pod;
import com.draemoncode.weixindb.domain.B_XiaZhu;
import com.draemoncode.weixindb.repository.B_PodRepository;
import com.draemoncode.weixindb.repository.B_XiaZhuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

@Component
public class BusiAssert {

    @Autowired
    private B_PodRepository b_podRepository;

    @Autowired
    private B_XiaZhuRepository b_xiaZhuRepository;

    public void assertNoPod(){
        B_Pod pod = b_podRepository.findByFlag(PodFlagConstant.ING);
        Assert.isNull(pod, "有一局还没结束, 不能上庄");
    }

    public void assertCurrPod(Integer syncid, String username){
        B_Pod pod = b_podRepository.findByFlag(PodFlagConstant.ING);
        Assert.isTrue(!pod.getZhuang_name().equals(username), "庄家不能下注");
        Assert.isTrue(pod.getId().equals(syncid), "不是这一局, 数据不合法");
    }

    public void assertMemberNotXiaZhu(Integer podId, Integer memberId){
        B_XiaZhu byPod_idAndMember_id = b_xiaZhuRepository.findByPod_idAndMember_id(podId, memberId);
        Assert.isNull(byPod_idAndMember_id, "会员本局已下注, 不能重复下注");
    }

}
